//
//  GameData.cpp
//  QuizMaster
//
//  Created by Jeppe Nielsen on 3/22/15.
//  Copyright (c) 2015 Jeppe Nielsen. All rights reserved.
//

#include "GameData.hpp"
#include <vector>
#include "MathHelper.hpp"

GameData::GameData() : CurrentQuestion(this), CurrentPlayer(this), PlayerToAnswerQuestion(this) {
    CurrentQuestion = 0;
    CurrentPlayer = 0;
    PlayerToAnswerQuestion = 0;
    
    Players[0].color = Colour::Green();
    Players[1].color =Colour::Red();
    Players[2].color =Colour::Blue();
    Players[3].color =Colour::Yellow();
    
    
    Players[0].Name = "Grøn";
    Players[1].Name = "Rød";
    Players[2].Name = "Blå";
    Players[3].Name = "Gul";
    
    CurrentPlayer = &Players[0];
    
    IsGameFinished = false;
}

GameData::~GameData() { }

void GameData::EnabledAllBuzzers() {
    for (int i=0; i<4; i++) {
        Players[i].BuzzerEnabled = true;
    }
}

void GameData::ResetPlayers() {
    for (int i=0; i<4; i++) {
        Players[i].Reset();
    }
}

void GameData::SelectRandomPlayer() {
    std::vector<GamePlayer*> players;
    for (int i=0; i<4; i++) {
        if (Players[i].IsPlaying) {
            players.push_back(&Players[i]);
        }
    }
    CurrentPlayer = players[MathHelper::Random((int)players.size())];
}
